<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perldebtut - Perl debugging tutorial - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perldebtut">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perldebtut.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perldebtut">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perldebtut">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perldebtut">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perldebtut">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perldebtut">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perldebtut">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perldebtut">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perldebtut">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perldebtut">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perldebtut">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perldebtut">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perldebtut">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perldebtut">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perldebtut">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perldebtut">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perldebtut">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perldebtut">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perldebtut">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perldebtut">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perldebtut">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perldebtut">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perldebtut">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perldebtut">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perldebtut">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perldebtut">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perldebtut">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perldebtut">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perldebtut">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perldebtut">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perldebtut">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perldebtut">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perldebtut">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perldebtut">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perldebtut">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perldebtut">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perldebtut">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perldebtut">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perldebtut">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perldebtut">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perldebtut">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perldebtut">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perldebtut">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perldebtut">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perldebtut">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perldebtut">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perldebtut">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perldebtut">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perldebtut">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perldebtut">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perldebtut">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perldebtut">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perldebtut">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perldebtut">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perldebtut">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perldebtut">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perldebtut">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perldebtut">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perldebtut">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perldebtut">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perldebtut">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perldebtut">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perldebtut">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perldebtut">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perldebtut">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perldebtut">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perldebtut">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perldebtut">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perldebtut">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perldebtut">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perldebtut">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perldebtut">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perldebtut">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perldebtut">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perldebtut">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perldebtut">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perldebtut">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perldebtut">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perldebtut">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perldebtut">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perldebtut">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perldebtut.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perldebtut">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perldebtut">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perldebtut">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perldebtut">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perldebtut">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perldebtut">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perldebtut">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perldebtut">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perldebtut">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perldebtut">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perldebtut">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perldebtut">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perldebtut">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perldebtut">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perldebtut">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perldebtut">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perldebtut">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perldebtut">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perldebtut">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perldebtut">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perldebtut">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perldebtut">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perldebtut">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perldebtut">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perldebtut">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perldebtut">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perldebtut">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perldebtut">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perldebtut">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perldebtut">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perldebtut">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perldebtut">5.35.1</a>
          <a class="dropdown-item active" href="perldebtut.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perldebtut.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perldebtut.html">perldebtut</a>
          <div id="more">
            (<a href="perldebtut.txt">source</a>,
            <a href="https://metacpan.org/pod/perldebtut">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#use-strict">use strict</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#Looking-at-data-and-w-and-v">Looking at data and -w and v</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#help">help</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#Stepping-through-code">Stepping through code</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#Placeholder-for-a,-w,-t,-T">Placeholder for a, w, t, T</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#REGULAR-EXPRESSIONS">REGULAR EXPRESSIONS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#OUTPUT-TIPS">OUTPUT TIPS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#CGI">CGI</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#GUIs">GUIs</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#SUMMARY">SUMMARY</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perldebtut.html#CONTRIBUTORS">CONTRIBUTORS</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perldebtut.html#NAME">#</a>NAME</h1>

<p>perldebtut - Perl debugging tutorial</p>

<h1 id="DESCRIPTION"><a class="permalink" href="perldebtut.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>A (very) lightweight introduction in the use of the perl debugger, and a pointer to existing, deeper sources of information on the subject of debugging perl programs.</p>

<p>There&#39;s an extraordinary number of people out there who don&#39;t appear to know anything about using the perl debugger, though they use the language every day. This is for them.</p>

<h1 id="use-strict"><a class="permalink" href="perldebtut.html#use-strict">#</a><a id="use"></a>use strict</h1>

<p>First of all, there&#39;s a few things you can do to make your life a lot more straightforward when it comes to debugging perl programs, without using the debugger at all. To demonstrate, here&#39;s a simple script, named &quot;hello&quot;, with a problem:</p>

<pre><code>#!/usr/bin/perl

$var1 = &#39;Hello World&#39;; # always wanted to do that :-)
$var2 = &quot;$varl\n&quot;;

print $var2; 
exit;</code></pre>

<p>While this compiles and runs happily, it probably won&#39;t do what&#39;s expected, namely it doesn&#39;t print &quot;Hello World\n&quot; at all; It will on the other hand do exactly what it was told to do, computers being a bit that way inclined. That is, it will print out a newline character, and you&#39;ll get what looks like a blank line. It looks like there&#39;s 2 variables when (because of the typo) there&#39;s really 3:</p>

<pre><code>$var1 = &#39;Hello World&#39;;
$varl = undef;
$var2 = &quot;\n&quot;;</code></pre>

<p>To catch this kind of problem, we can force each variable to be declared before use by pulling in the strict module, by putting &#39;use strict;&#39; after the first line of the script.</p>

<p>Now when you run it, perl complains about the 3 undeclared variables and we get four error messages because one variable is referenced twice:</p>

<pre><code>Global symbol &quot;$var1&quot; requires explicit package name at ./t1 line 4.
Global symbol &quot;$var2&quot; requires explicit package name at ./t1 line 5.
Global symbol &quot;$varl&quot; requires explicit package name at ./t1 line 5.
Global symbol &quot;$var2&quot; requires explicit package name at ./t1 line 7.
Execution of ./hello aborted due to compilation errors.     </code></pre>

<p>Luvverly! and to fix this we declare all variables explicitly and now our script looks like this:</p>

<pre><code>#!/usr/bin/perl
use strict;

my $var1 = &#39;Hello World&#39;;
my $varl = undef;
my $var2 = &quot;$varl\n&quot;;

print $var2; 
exit;</code></pre>

<p>We then do (always a good idea) a syntax check before we try to run it again:</p>

<pre><code class="plaintext">&gt; perl -c hello
hello syntax OK </code></pre>

<p>And now when we run it, we get &quot;\n&quot; still, but at least we know why. Just getting this script to compile has exposed the &#39;$varl&#39; (with the letter &#39;l&#39;) variable, and simply changing $varl to $var1 solves the problem.</p>

<h1 id="Looking-at-data-and-w-and-v"><a class="permalink" href="perldebtut.html#Looking-at-data-and-w-and-v">#</a><a id="Looking"></a><a id="Looking-at-data-and--w-and-v"></a>Looking at data and -w and v</h1>

<p>Ok, but how about when you want to really see your data, what&#39;s in that dynamic variable, just before using it?</p>

<pre><code>#!/usr/bin/perl 
use strict;

my $key = &#39;welcome&#39;;
my %data = (
	&#39;this&#39; =&gt; qw(that), 
	&#39;tom&#39; =&gt; qw(and jerry),
	&#39;welcome&#39; =&gt; q(Hello World),
	&#39;zip&#39; =&gt; q(welcome),
);
my @data = keys %data;

print &quot;$data{$key}\n&quot;;
exit;                               </code></pre>

<p>Looks OK, after it&#39;s been through the syntax check (perl -c scriptname), we run it and all we get is a blank line again! Hmmmm.</p>

<p>One common debugging approach here, would be to liberally sprinkle a few print statements, to add a check just before we print out our data, and another just after:</p>

<pre><code>print &quot;All OK\n&quot; if grep($key, keys %data);
print &quot;$data{$key}\n&quot;;
print &quot;done: &#39;$data{$key}&#39;\n&quot;;</code></pre>

<p>And try again:</p>

<pre><code class="plaintext">&gt; perl data
All OK     

done: &#39;&#39;</code></pre>

<p>After much staring at the same piece of code and not seeing the wood for the trees for some time, we get a cup of coffee and try another approach. That is, we bring in the cavalry by giving perl the &#39;<b>-d</b>&#39; switch on the command line:</p>

<pre><code>&gt; perl -d data 
Default die handler restored.

Loading DB routines from perl5db.pl version 1.07
Editor support available.

Enter h or `h h&#39; for help, or `man perldebug&#39; for more help.

main::(./data:4):     my $key = &#39;welcome&#39;;   </code></pre>

<p>Now, what we&#39;ve done here is to launch the built-in perl debugger on our script. It&#39;s stopped at the first line of executable code and is waiting for input.</p>

<p>Before we go any further, you&#39;ll want to know how to quit the debugger: use just the letter &#39;<b>q</b>&#39;, not the words &#39;quit&#39; or &#39;exit&#39;:</p>

<pre><code class="plaintext">DB&lt;1&gt; q
&gt;</code></pre>

<p>That&#39;s it, you&#39;re back on home turf again.</p>

<h1 id="help"><a class="permalink" href="perldebtut.html#help">#</a>help</h1>

<p>Fire the debugger up again on your script and we&#39;ll look at the help menu. There&#39;s a couple of ways of calling help: a simple &#39;<b>h</b>&#39; will get the summary help list, &#39;<b>|h</b>&#39; (pipe-h) will pipe the help through your pager (which is (probably &#39;more&#39; or &#39;less&#39;), and finally, &#39;<b>h h</b>&#39; (h-space-h) will give you the entire help screen. Here is the summary page:</p>

<p>D<b>1</b>h</p>

<pre><code class="plaintext">List/search source lines:               Control script execution:
 l [ln|sub]  List source code            T           Stack trace
 - or .      List previous/current line  s [expr]    Single step
                                                              [in expr]
 v [line]    View around line            n [expr]    Next, steps over
                                                                   subs
 f filename  View source in file         &lt;CR/Enter&gt;  Repeat last n or s
 /pattern/ ?patt?   Search forw/backw    r           Return from
                                                             subroutine
 M           Show module versions        c [ln|sub]  Continue until
                                                               position
Debugger controls:                       L           List break/watch/
                                                                actions
 o [...]     Set debugger options        t [expr]    Toggle trace
                                                           [trace expr]
 &lt;[&lt;]|{[{]|&gt;[&gt;] [cmd] Do pre/post-prompt b [ln|event|sub] [cnd] Set
                                                             breakpoint
 ! [N|pat]   Redo a previous command     B ln|*      Delete a/all
                                                            breakpoints
 H [-num]    Display last num commands   a [ln] cmd  Do cmd before line
 = [a val]   Define/list an alias        A ln|*      Delete a/all
                                                                actions
 h [db_cmd]  Get help on command         w expr      Add a watch
                                                             expression
 h h         Complete help page          W expr|*    Delete a/all watch
                                                                  exprs
 |[|]db_cmd  Send output to pager        ![!] syscmd Run cmd in a
                                                             subprocess
 q or ^D     Quit                        R           Attempt a restart
Data Examination:     expr     Execute perl code, also see: s,n,t expr
 x|m expr       Evals expr in list context, dumps the result or lists
                                                               methods.
 p expr         Print expression (uses script&#39;s current package).
 S [[!]pat]     List subroutine names [not] matching pattern
 V [Pk [Vars]]  List Variables in Package.  Vars can be ~pattern or
                                                              !pattern.
 X [Vars]       Same as &quot;V current_package [Vars]&quot;.
 y [n [Vars]]   List lexicals in higher scope &lt;n&gt;.  Vars same as V.
For more help, type h cmd_letter, or run man perldebug for all docs. </code></pre>

<p>More confusing options than you can shake a big stick at! It&#39;s not as bad as it looks and it&#39;s very useful to know more about all of it, and fun too!</p>

<p>There&#39;s a couple of useful ones to know about straight away. You wouldn&#39;t think we&#39;re using any libraries at all at the moment, but &#39;<b>M</b>&#39; will show which modules are currently loaded, and their version number, while &#39;<b>m</b>&#39; will show the methods, and &#39;<b>S</b>&#39; shows all subroutines (by pattern) as shown below. &#39;<b>V</b>&#39; and &#39;<b>X</b>&#39; show variables in the program by package scope and can be constrained by pattern.</p>

<pre><code class="plaintext">DB&lt;2&gt;S str 
dumpvar::stringify
strict::bits
strict::import
strict::unimport  </code></pre>

<p>Using &#39;X&#39; and cousins requires you not to use the type identifiers ($@%), just the &#39;name&#39;:</p>

<pre><code class="plaintext">DM&lt;3&gt;X ~err
FileHandle(stderr) =&gt; fileno(2)    </code></pre>

<p>Remember we&#39;re in our tiny program with a problem, we should have a look at where we are, and what our data looks like. First of all let&#39;s view some code at our present position (the first line of code in this case), via &#39;<b>v</b>&#39;:</p>

<pre><code>DB&lt;4&gt; v
1       #!/usr/bin/perl
2:      use strict;
3
4==&gt;    my $key = &#39;welcome&#39;;
5:      my %data = (
6               &#39;this&#39; =&gt; qw(that),
7               &#39;tom&#39; =&gt; qw(and jerry),
8               &#39;welcome&#39; =&gt; q(Hello World),
9               &#39;zip&#39; =&gt; q(welcome),
10      );                                 </code></pre>

<p>At line number 4 is a helpful pointer, that tells you where you are now. To see more code, type &#39;v&#39; again:</p>

<pre><code>DB&lt;4&gt; v
8               &#39;welcome&#39; =&gt; q(Hello World),
9               &#39;zip&#39; =&gt; q(welcome),
10      );
11:     my @data = keys %data;
12:     print &quot;All OK\n&quot; if grep($key, keys %data);
13:     print &quot;$data{$key}\n&quot;;
14:     print &quot;done: &#39;$data{$key}&#39;\n&quot;;
15:     exit;      </code></pre>

<p>And if you wanted to list line 5 again, type &#39;l 5&#39;, (note the space):</p>

<pre><code>DB&lt;4&gt; l 5
5:      my %data = (</code></pre>

<p>In this case, there&#39;s not much to see, but of course normally there&#39;s pages of stuff to wade through, and &#39;l&#39; can be very useful. To reset your view to the line we&#39;re about to execute, type a lone period &#39;.&#39;:</p>

<pre><code>DB&lt;5&gt; .
main::(./data_a:4):     my $key = &#39;welcome&#39;;  </code></pre>

<p>The line shown is the one that is about to be executed <b>next</b>, it hasn&#39;t happened yet. So while we can print a variable with the letter &#39;<b>p</b>&#39;, at this point all we&#39;d get is an empty (undefined) value back. What we need to do is to step through the next executable statement with an &#39;<b>s</b>&#39;:</p>

<pre><code>DB&lt;6&gt; s
main::(./data_a:5):     my %data = (
main::(./data_a:6):             &#39;this&#39; =&gt; qw(that),
main::(./data_a:7):             &#39;tom&#39; =&gt; qw(and jerry),
main::(./data_a:8):             &#39;welcome&#39; =&gt; q(Hello World),
main::(./data_a:9):             &#39;zip&#39; =&gt; q(welcome),
main::(./data_a:10):    );   </code></pre>

<p>Now we can have a look at that first ($key) variable:</p>

<pre><code>DB&lt;7&gt; p $key 
welcome </code></pre>

<p>line 13 is where the action is, so let&#39;s continue down to there via the letter &#39;<b>c</b>&#39;, which by the way, inserts a &#39;one-time-only&#39; breakpoint at the given line or sub routine:</p>

<pre><code>DB&lt;8&gt; c 13
All OK
main::(./data_a:13):    print &quot;$data{$key}\n&quot;;</code></pre>

<p>We&#39;ve gone past our check (where &#39;All OK&#39; was printed) and have stopped just before the meat of our task. We could try to print out a couple of variables to see what is happening:</p>

<pre><code>DB&lt;9&gt; p $data{$key}</code></pre>

<p>Not much in there, lets have a look at our hash:</p>

<pre><code>DB&lt;10&gt; p %data
Hello Worldziptomandwelcomejerrywelcomethisthat 

DB&lt;11&gt; p keys %data
Hello Worldtomwelcomejerrythis  </code></pre>

<p>Well, this isn&#39;t very easy to read, and using the helpful manual (<b>h h</b>), the &#39;<b>x</b>&#39; command looks promising:</p>

<pre><code>DB&lt;12&gt; x %data
0  &#39;Hello World&#39;
1  &#39;zip&#39;
2  &#39;tom&#39;
3  &#39;and&#39;
4  &#39;welcome&#39;
5  undef
6  &#39;jerry&#39;
7  &#39;welcome&#39;
8  &#39;this&#39;
9  &#39;that&#39;     </code></pre>

<p>That&#39;s not much help, a couple of welcomes in there, but no indication of which are keys, and which are values, it&#39;s just a listed array dump and, in this case, not particularly helpful. The trick here, is to use a <b>reference</b> to the data structure:</p>

<pre><code>DB&lt;13&gt; x \%data
0  HASH(0x8194bc4)
   &#39;Hello World&#39; =&gt; &#39;zip&#39;
   &#39;jerry&#39; =&gt; &#39;welcome&#39;
   &#39;this&#39; =&gt; &#39;that&#39;
   &#39;tom&#39; =&gt; &#39;and&#39;
   &#39;welcome&#39; =&gt; undef  </code></pre>

<p>The reference is truly dumped and we can finally see what we&#39;re dealing with. Our quoting was perfectly valid but wrong for our purposes, with &#39;and jerry&#39; being treated as 2 separate words rather than a phrase, thus throwing the evenly paired hash structure out of alignment.</p>

<p>The &#39;<b>-w</b>&#39; switch would have told us about this, had we used it at the start, and saved us a lot of trouble:</p>

<pre><code class="plaintext">&gt; perl -w data
Odd number of elements in hash assignment at ./data line 5.    </code></pre>

<p>We fix our quoting: &#39;tom&#39; =&gt; q(and jerry), and run it again, this time we get our expected output:</p>

<pre><code class="plaintext">&gt; perl -w data
Hello World</code></pre>

<p>While we&#39;re here, take a closer look at the &#39;<b>x</b>&#39; command, it&#39;s really useful and will merrily dump out nested references, complete objects, partial objects - just about whatever you throw at it:</p>

<p>Let&#39;s make a quick object and x-plode it, first we&#39;ll start the debugger: it wants some form of input from STDIN, so we give it something non-committal, a zero:</p>

<pre><code class="plaintext">&gt; perl -de 0
Default die handler restored.

Loading DB routines from perl5db.pl version 1.07
Editor support available.

Enter h or `h h&#39; for help, or `man perldebug&#39; for more help.

main::(-e:1):   0</code></pre>

<p>Now build an on-the-fly object over a couple of lines (note the backslash):</p>

<pre><code>DB&lt;1&gt; $obj = bless({&#39;unique_id&#39;=&gt;&#39;123&#39;, &#39;attr&#39;=&gt; \
cont: 	{&#39;col&#39; =&gt; &#39;black&#39;, &#39;things&#39; =&gt; [qw(this that etc)]}}, &#39;MY_class&#39;)</code></pre>

<p>And let&#39;s have a look at it:</p>

<pre><code> 	DB&lt;2&gt; x $obj
0  MY_class=HASH(0x828ad98)
  		&#39;attr&#39; =&gt; HASH(0x828ad68)
     	&#39;col&#39; =&gt; &#39;black&#39;
     	&#39;things&#39; =&gt; ARRAY(0x828abb8)
        	0  &#39;this&#39;
        	1  &#39;that&#39;
        	2  &#39;etc&#39;
  		&#39;unique_id&#39; =&gt; 123       
 	DB&lt;3&gt;</code></pre>

<p>Useful, huh? You can eval nearly anything in there, and experiment with bits of code or regexes until the cows come home:</p>

<pre><code>DB&lt;3&gt; @data = qw(this that the other atheism leather theory scythe)

DB&lt;4&gt; p &#39;saw -&gt; &#39;.($cnt += map { print &quot;\t:\t$_\n&quot; } grep(/the/, sort @data))
atheism
leather
other
scythe
the
theory
saw -&gt; 6</code></pre>

<p>If you want to see the command History, type an &#39;<b>H</b>&#39;:</p>

<pre><code>DB&lt;5&gt; H
4: p &#39;saw -&gt; &#39;.($cnt += map { print &quot;\t:\t$_\n&quot; } grep(/the/, sort @data))
3: @data = qw(this that the other atheism leather theory scythe)
2: x $obj
1: $obj = bless({&#39;unique_id&#39;=&gt;&#39;123&#39;, &#39;attr&#39;=&gt;
{&#39;col&#39; =&gt; &#39;black&#39;, &#39;things&#39; =&gt; [qw(this that etc)]}}, &#39;MY_class&#39;)
DB&lt;5&gt;</code></pre>

<p>And if you want to repeat any previous command, use the exclamation: &#39;<b>!</b>&#39;:</p>

<pre><code>DB&lt;5&gt; !4
p &#39;saw -&gt; &#39;.($cnt += map { print &quot;$_\n&quot; } grep(/the/, sort @data))
atheism
leather
other
scythe
the
theory
saw -&gt; 12</code></pre>

<p>For more on references see <a href="perlref.html">perlref</a> and <a href="perlreftut.html">perlreftut</a></p>

<h1 id="Stepping-through-code"><a class="permalink" href="perldebtut.html#Stepping-through-code">#</a><a id="Stepping"></a>Stepping through code</h1>

<p>Here&#39;s a simple program which converts between Celsius and Fahrenheit, it too has a problem:</p>

<pre><code> #!/usr/bin/perl -w
 use strict;

 my $arg = $ARGV[0] || &#39;-c20&#39;;

 if ($arg =~ /^\-(c|f)((\-|\+)*\d+(\.\d+)*)$/) {
	my ($deg, $num) = ($1, $2);
	my ($in, $out) = ($num, $num);
	if ($deg eq &#39;c&#39;) {
		$deg = &#39;f&#39;;
		$out = &amp;c2f($num);
	} else {
		$deg = &#39;c&#39;;
		$out = &amp;f2c($num);
	}
	$out = sprintf(&#39;%0.2f&#39;, $out);
	$out =~ s/^((\-|\+)*\d+)\.0+$/$1/;
	print &quot;$out $deg\n&quot;;
 } else {
	print &quot;Usage: $0 -[c|f] num\n&quot;;
 }
 exit;

 sub f2c {
	my $f = shift;
	my $c = 5 * $f - 32 / 9;
	return $c;
 }

 sub c2f {
	my $c = shift;
	my $f = 9 * $c / 5 + 32;
	return $f;
 }</code></pre>

<p>For some reason, the Fahrenheit to Celsius conversion fails to return the expected output. This is what it does:</p>

<pre><code class="plaintext">&gt; temp -c0.72
33.30 f

&gt; temp -f33.3
162.94 c</code></pre>

<p>Not very consistent! We&#39;ll set a breakpoint in the code manually and run it under the debugger to see what&#39;s going on. A breakpoint is a flag, to which the debugger will run without interruption, when it reaches the breakpoint, it will stop execution and offer a prompt for further interaction. In normal use, these debugger commands are completely ignored, and they are safe - if a little messy, to leave in production code.</p>

<pre><code>my ($in, $out) = ($num, $num);
$DB::single=2; # insert at line 9!
if ($deg eq &#39;c&#39;) 
	...

&gt; perl -d temp -f33.3
Default die handler restored.

Loading DB routines from perl5db.pl version 1.07
Editor support available.

Enter h or `h h&#39; for help, or `man perldebug&#39; for more help.

main::(temp:4): my $arg = $ARGV[0] || &#39;-c100&#39;;     </code></pre>

<p>We&#39;ll simply continue down to our pre-set breakpoint with a &#39;<b>c</b>&#39;:</p>

<pre><code>  	DB&lt;1&gt; c
	main::(temp:10):                if ($deg eq &#39;c&#39;) {   </code></pre>

<p>Followed by a view command to see where we are:</p>

<pre><code>DB&lt;1&gt; v
7:              my ($deg, $num) = ($1, $2);
8:              my ($in, $out) = ($num, $num);
9:              $DB::single=2;
10==&gt;           if ($deg eq &#39;c&#39;) {
11:                     $deg = &#39;f&#39;;
12:                     $out = &amp;c2f($num);
13              } else {
14:                     $deg = &#39;c&#39;;
15:                     $out = &amp;f2c($num);
16              }                             </code></pre>

<p>And a print to show what values we&#39;re currently using:</p>

<pre><code>DB&lt;1&gt; p $deg, $num
f33.3</code></pre>

<p>We can put another break point on any line beginning with a colon, we&#39;ll use line 17 as that&#39;s just as we come out of the subroutine, and we&#39;d like to pause there later on:</p>

<pre><code class="plaintext">DB&lt;2&gt; b 17</code></pre>

<p>There&#39;s no feedback from this, but you can see what breakpoints are set by using the list &#39;L&#39; command:</p>

<pre><code>	DB&lt;3&gt; L
	temp:
 		17:            print &quot;$out $deg\n&quot;;
   		break if (1)     </code></pre>

<p>Note that to delete a breakpoint you use &#39;B&#39;.</p>

<p>Now we&#39;ll continue down into our subroutine, this time rather than by line number, we&#39;ll use the subroutine name, followed by the now familiar &#39;v&#39;:</p>

<pre><code>DB&lt;3&gt; c f2c
main::f2c(temp:30):             my $f = shift;  

DB&lt;4&gt; v
24:     exit;
25
26      sub f2c {
27==&gt;           my $f = shift;
28:             my $c = 5 * $f - 32 / 9; 
29:             return $c;
30      }
31
32      sub c2f {
33:             my $c = shift;   </code></pre>

<p>Note that if there was a subroutine call between us and line 29, and we wanted to <b>single-step</b> through it, we could use the &#39;<b>s</b>&#39; command, and to step over it we would use &#39;<b>n</b>&#39; which would execute the sub, but not descend into it for inspection. In this case though, we simply continue down to line 29:</p>

<pre><code>DB&lt;4&gt; c 29  
main::f2c(temp:29):             return $c;</code></pre>

<p>And have a look at the return value:</p>

<pre><code>DB&lt;5&gt; p $c
162.944444444444</code></pre>

<p>This is not the right answer at all, but the sum looks correct. I wonder if it&#39;s anything to do with operator precedence? We&#39;ll try a couple of other possibilities with our sum:</p>

<pre><code>DB&lt;6&gt; p (5 * $f - 32 / 9)
162.944444444444

DB&lt;7&gt; p 5 * $f - (32 / 9) 
162.944444444444

DB&lt;8&gt; p (5 * $f) - 32 / 9
162.944444444444

DB&lt;9&gt; p 5 * ($f - 32) / 9
0.722222222222221</code></pre>

<p>:-) that&#39;s more like it! Ok, now we can set our return variable and we&#39;ll return out of the sub with an &#39;r&#39;:</p>

<pre><code>DB&lt;10&gt; $c = 5 * ($f - 32) / 9

DB&lt;11&gt; r
scalar context return from main::f2c: 0.722222222222221</code></pre>

<p>Looks good, let&#39;s just continue off the end of the script:</p>

<pre><code class="plaintext">	DB&lt;12&gt; c
	0.72 c 
	Debugged program terminated.  Use q to quit or R to restart,
  	use O inhibit_exit to avoid stopping after program termination,
  	h q, h R or h O to get additional info.   </code></pre>

<p>A quick fix to the offending line (insert the missing parentheses) in the actual program and we&#39;re finished.</p>

<h1 id="Placeholder-for-a,-w,-t,-T"><a class="permalink" href="perldebtut.html#Placeholder-for-a,-w,-t,-T">#</a><a id="Placeholder"></a><a id="Placeholder-for-a-w-t-T"></a>Placeholder for a, w, t, T</h1>

<p>Actions, watch variables, stack traces etc.: on the TODO list.</p>

<pre><code class="plaintext">a 

w 

t 

T</code></pre>

<h1 id="REGULAR-EXPRESSIONS"><a class="permalink" href="perldebtut.html#REGULAR-EXPRESSIONS">#</a><a id="REGULAR"></a>REGULAR EXPRESSIONS</h1>

<p>Ever wanted to know what a regex looked like? You&#39;ll need perl compiled with the DEBUGGING flag for this one:</p>

<pre><code class="plaintext">&gt; perl -Dr -e &#39;/^pe(a)*rl$/i&#39;
Compiling REx `^pe(a)*rl$&#39;
size 17 first at 2
rarest char
 at 0
   1: BOL(2)
   2: EXACTF &lt;pe&gt;(4)
   4: CURLYN[1] {0,32767}(14)
   6:   NOTHING(8)
   8:   EXACTF &lt;a&gt;(0)
  12:   WHILEM(0)
  13: NOTHING(14)
  14: EXACTF &lt;rl&gt;(16)
  16: EOL(17)
  17: END(0)
floating `&#39;$ at 4..2147483647 (checking floating) stclass
  `EXACTF &lt;pe&gt;&#39; anchored(BOL) minlen 4
Omitting $` $&amp; $&#39; support.

EXECUTING...

Freeing REx: `^pe(a)*rl$&#39;</code></pre>

<p>Did you really want to know? :-) For more gory details on getting regular expressions to work, have a look at <a href="perlre.html">perlre</a>, <a href="perlretut.html">perlretut</a>, and to decode the mysterious labels (BOL and CURLYN, etc. above), see <a href="perldebguts.html">perldebguts</a>.</p>

<h1 id="OUTPUT-TIPS"><a class="permalink" href="perldebtut.html#OUTPUT-TIPS">#</a><a id="OUTPUT"></a>OUTPUT TIPS</h1>

<p>To get all the output from your error log, and not miss any messages via helpful operating system buffering, insert a line like this, at the start of your script:</p>

<pre><code>$|=1;	</code></pre>

<p>To watch the tail of a dynamically growing logfile, (from the command line):</p>

<pre><code>tail -f $error_log</code></pre>

<p>Wrapping all die calls in a handler routine can be useful to see how, and from where, they&#39;re being called, <a href="perlvar.html">perlvar</a> has more information:</p>

<pre><code>BEGIN { $SIG{__DIE__} = sub { require Carp; Carp::confess(@_) } }</code></pre>

<p>Various useful techniques for the redirection of STDOUT and STDERR filehandles are explained in <a href="perlopentut.html">perlopentut</a> and <a href="perlfaq8.html">perlfaq8</a>.</p>

<h1 id="CGI"><a class="permalink" href="perldebtut.html#CGI">#</a>CGI</h1>

<p>Just a quick hint here for all those CGI programmers who can&#39;t figure out how on earth to get past that &#39;waiting for input&#39; prompt, when running their CGI script from the command-line, try something like this:</p>

<pre><code class="plaintext">&gt; perl -d my_cgi.pl -nodebug </code></pre>

<p>Of course <a href="CGI.html">CGI</a> and <a href="perlfaq9.html">perlfaq9</a> will tell you more.</p>

<h1 id="GUIs"><a class="permalink" href="perldebtut.html#GUIs">#</a>GUIs</h1>

<p>The command line interface is tightly integrated with an <b>emacs</b> extension and there&#39;s a <b>vi</b> interface too.</p>

<p>You don&#39;t have to do this all on the command line, though, there are a few GUI options out there. The nice thing about these is you can wave a mouse over a variable and a dump of its data will appear in an appropriate window, or in a popup balloon, no more tiresome typing of &#39;x $varname&#39; :-)</p>

<p>In particular have a hunt around for the following:</p>

<p><b>ptkdb</b> perlTK based wrapper for the built-in debugger</p>

<p><b>ddd</b> data display debugger</p>

<p><b>PerlDevKit</b> and <b>PerlBuilder</b> are NT specific</p>

<p>NB. (more info on these and others would be appreciated).</p>

<h1 id="SUMMARY"><a class="permalink" href="perldebtut.html#SUMMARY">#</a>SUMMARY</h1>

<p>We&#39;ve seen how to encourage good coding practices with <b>use strict</b> and <b>-w</b>. We can run the perl debugger <b>perl -d scriptname</b> to inspect your data from within the perl debugger with the <b>p</b> and <b>x</b> commands. You can walk through your code, set breakpoints with <b>b</b> and step through that code with <b>s</b> or <b>n</b>, continue with <b>c</b> and return from a sub with <b>r</b>. Fairly intuitive stuff when you get down to it.</p>

<p>There is of course lots more to find out about, this has just scratched the surface. The best way to learn more is to use perldoc to find out more about the language, to read the on-line help (<a href="perldebug.html">perldebug</a> is probably the next place to go), and of course, experiment.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="perldebtut.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="perldebug.html">perldebug</a>, <a href="perldebguts.html">perldebguts</a>, <a href="perl5db.pl">perl5db.pl</a>, <a href="perldiag.html">perldiag</a>, <a href="perlrun.html">perlrun</a></p>

<h1 id="AUTHOR"><a class="permalink" href="perldebtut.html#AUTHOR">#</a>AUTHOR</h1>

<p>Richard Foley &lt;richard.foley@rfi.net&gt; Copyright (c) 2000</p>

<h1 id="CONTRIBUTORS"><a class="permalink" href="perldebtut.html#CONTRIBUTORS">#</a>CONTRIBUTORS</h1>

<p>Various people have made helpful suggestions and contributions, in particular:</p>

<p>Ronald J Kimball &lt;rjk@linguist.dartmouth.edu&gt;</p>

<p>Hugo van der Sanden &lt;hv@crypt0.demon.co.uk&gt;</p>

<p>Peter Scott &lt;Peter@PSDT.com&gt;</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
